package com.pingan.license.controller;

import com.pingan.license.utils.EncryUtil;
import org.springframework.beans.factory.annotation.Value;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @AUTHOR:LIUCHAO;
 * @DATE: 2020/12/1 9:03
 */

public class UserController {
    @Value("${Key}")
    private String Key;//读取config文件中的key值
    //解密
    public Boolean desDecode(String str) {
        String t = "";
        //System.out.println("加密后：" + EncryUtil.encrypt(t));
        t = EncryUtil.decrypt(str);
        //System.out.println("解密后：" + t);
        if(t.equals("perpetual license")) {
            return true;
        }else {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date date = new Date();
            String nowDate = format.format(date);
            Integer result = EncryUtil.compareDate(t,nowDate);
            if(result == -1) {
                return false;
            }
        }

        return true;
    }
    //加密
    public String desCode(String str) {
        //str为加密的截止日期
        String t = EncryUtil.encrypt(str);
        //System.out.println("加密后：" + t);
        return t;
    }
}
